package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.validation.StorageComValidator;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "csf_assurance")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfAssurance extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50, index = true, unique = true)
    private String code;

    @One(value = "loan", target = CsfLoan.class, groups = {"CsfAssurance.search","CsfAssurance.detail"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long loanId;

    /** 被担保企业id **/
    @One(value = "voucheeCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, validators = StorageComValidator.class)
    private Long voucheeId;

    /** 担保企业 **/
    @One(value = "assureCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long assureId;

    @One(value = "bank", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long bankId;

    private BigDecimal contractAmount;

    private BigDecimal amount;

    private Date endDate;

    /**
     *  货物反担保确认
     */
    private boolean buyerConfirm;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getVoucheeId() {
        return voucheeId;
    }

    public void setVoucheeId(Long voucheeId) {
        this.voucheeId = voucheeId;
    }

    public Long getAssureId() {
        return assureId;
    }

    public void setAssureId(Long assureId) {
        this.assureId = assureId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public BigDecimal getContractAmount() {
        return contractAmount;
    }

    public void setContractAmount(BigDecimal contractAmount) {
        this.contractAmount = contractAmount;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public boolean isBuyerConfirm() {
        return buyerConfirm;
    }

    public void setBuyerConfirm(boolean buyerConfirm) {
        this.buyerConfirm = buyerConfirm;
    }
}
